home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / msds-prl / dpmi.taz / dpmi / perl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  23.7 KB  |  1,073 lines

  1. /* $RCSfile: perl.h $$Revision: 1.1 $$Date: 92/11/10 09:28:37 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * [ Marc Pawlowsky, November 1992 ]
  9.  *    Modified file for Metaware's High C compiler.
  10.  * 
  11.  * Revision 4.0.1.6  92/06/08  14:55:10  lwall
  12.  * patch20: added Atari ST portability
  13.  * patch20: bcopy() and memcpy() now tested for overlap safety
  14.  * patch20: Perl now distinguishes overlapped copies from non-overlapped
  15.  * patch20: removed implicit int declarations on functions
  16.  * 
  17.  * Revision 4.0.1.5  91/11/11  16:41:07  lwall
  18.  * patch19: uts wrongly defines S_ISDIR() et al
  19.  * patch19: too many preprocessors can't expand a macro right in #if
  20.  * patch19: added little-endian pack/unpack options
  21.  * 
  22.  * Revision 4.0.1.4  91/11/05  18:06:10  lwall
  23.  * patch11: various portability fixes
  24.  * patch11: added support for dbz
  25.  * patch11: added some support for 64-bit integers
  26.  * patch11: hex() didn't understand leading 0x
  27.  * 
  28.  * Revision 4.0.1.3  91/06/10  01:25:10  lwall
  29.  * patch10: certain pattern optimizations were botched
  30.  * 
  31.  * Revision 4.0.1.2  91/06/07  11:28:33  lwall
  32.  * patch4: new copyright notice
  33.  * patch4: made some allowances for "semi-standard" C
  34.  * patch4: many, many itty-bitty portability fixes
  35.  * 
  36.  * Revision 4.0.1.1  91/04/11  17:49:51  lwall
  37.  * patch1: hopefully straightened out some of the Xenix mess
  38.  * 
  39.  * Revision 4.0  91/03/20  01:37:56  lwall
  40.  * 4.0 baseline.
  41.  * 
  42.  */
  43.  
  44. #ifdef __HIGHC__
  45.     #include "hc386.h"
  46. #endif
  47.  
  48. #define VOIDWANT 1
  49. #include "config.h"
  50.  
  51. #ifdef MYMALLOC
  52. #   ifdef HIDEMYMALLOC
  53. #    define malloc Mymalloc
  54. #    define realloc Myremalloc
  55. #    define free Myfree
  56. #   endif
  57. #   define safemalloc malloc
  58. #   define saferealloc realloc
  59. #   define safefree free
  60. #endif
  61.  
  62. /* work around some libPW problems */
  63. #define fatal Myfatal
  64. #ifdef DOINIT
  65. char Error[1];
  66. #endif
  67.  
  68. /* define this once if either system, instead of cluttering up the src */
  69. #if defined(MSDOS) || defined(atarist)
  70. #define DOSISH 1
  71. #endif
  72.  
  73. #ifdef DOSISH
  74. /* This stuff now in the MS-DOS config.h file. */
  75. #else /* !MSDOS */
  76.  
  77. /*
  78.  * The following symbols are defined if your operating system supports
  79.  * functions by that name.  All Unixes I know of support them, thus they
  80.  * are not checked by the configuration script, but are directly defined
  81.  * here.
  82.  */
  83. #define HAS_ALARM
  84. #define HAS_CHOWN
  85. #define HAS_CHROOT
  86. #define HAS_FORK
  87. #define HAS_GETLOGIN
  88. #define HAS_GETPPID
  89. #define HAS_KILL
  90. #define HAS_LINK
  91. #define HAS_PIPE
  92. #define HAS_WAIT
  93. #define HAS_UMASK
  94. /*
  95.  * The following symbols are defined if your operating system supports
  96.  * password and group functions in general.  All Unix systems do.
  97.  */
  98. #define HAS_GROUP
  99. #define HAS_PASSWD
  100.  
  101. #endif /* !MSDOS */
  102.  
  103. #if defined(__STDC__) || defined(_AIX) || defined(__stdc__)
  104. # define STANDARD_C 1
  105. #endif
  106.  
  107. #if defined(HASVOLATILE) || defined(STANDARD_C)
  108. #define VOLATILE volatile
  109. #else
  110. #define VOLATILE
  111. #endif
  112.  
  113. #ifdef IAMSUID
  114. #   ifndef TAINT
  115. #    define TAINT
  116. #   endif
  117. #endif
  118.  
  119. #ifndef HAS_VFORK
  120. #   define vfork fork
  121. #endif
  122.  
  123. #ifdef HAS_GETPGRP2
  124. #   ifndef HAS_GETPGRP
  125. #    define HAS_GETPGRP
  126. #   endif
  127. #   define getpgrp getpgrp2
  128. #endif
  129.  
  130. #ifdef HAS_SETPGRP2
  131. #   ifndef HAS_SETPGRP
  132. #    define HAS_SETPGRP
  133. #   endif
  134. #   define setpgrp setpgrp2
  135. #endif
  136.  
  137. #include <stdio.h>
  138. #include <ctype.h>
  139. #include <setjmp.h>
  140. #ifndef MSDOS
  141. #ifdef PARAM_NEEDS_TYPES
  142. #include <sys/types.h>
  143. #endif
  144. #include <sys/param.h>
  145. #endif
  146. #ifdef STANDARD_C
  147. /* Use all the "standard" definitions */
  148. #include <stdlib.h>
  149. #include <string.h>
  150. #define MEM_SIZE size_t
  151. #else
  152. typedef unsigned int MEM_SIZE;
  153. #endif /* STANDARD_C */
  154.  
  155. #if defined(HAS_MEMCMP) && defined(mips) && defined(ultrix)
  156. #undef HAS_MEMCMP
  157. #endif
  158.  
  159. #ifdef HAS_MEMCPY
  160. #  ifndef STANDARD_C
  161. #    ifndef memcpy
  162.     extern char * memcpy();
  163. #    endif
  164. #  endif
  165. #else
  166. #   ifndef memcpy
  167. #    ifdef HAS_BCOPY
  168. #        define memcpy(d,s,l) bcopy(s,d,l)
  169. #    else
  170. #        define memcpy(d,s,l) my_bcopy(s,d,l)
  171. #    endif
  172. #   endif
  173. #endif /* HAS_MEMCPY */
  174.  
  175. #ifdef HAS_MEMSET
  176. #  ifndef STANDARD_C
  177. #    ifndef memset
  178.     extern char *memset();
  179. #    endif
  180. #  endif
  181. #  define memzero(d,l) memset(d,0,l)
  182. #else
  183. #   ifndef memzero
  184. #    ifdef HAS_BZERO
  185. #        define memzero(d,l) bzero(d,l)
  186. #    else
  187. #        define memzero(d,l) my_bzero(d,l)
  188. #    endif
  189. #   endif
  190. #endif /* HAS_MEMSET */
  191.  
  192. #ifdef HAS_MEMCMP
  193. #  ifndef STANDARD_C
  194. #    ifndef memcmp
  195.     extern int memcmp();
  196. #    endif
  197. #  endif
  198. #else
  199. #   ifndef memcmp
  200. #    define memcmp(s1,s2,l) my_memcmp(s1,s2,l)
  201. #   endif
  202. #endif /* HAS_MEMCMP */
  203.  
  204. /* we prefer bcmp slightly for comparisons that don't care about ordering */
  205. #ifndef HAS_BCMP
  206. #   ifndef bcmp
  207. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  208. #   endif
  209. #endif /* HAS_BCMP */
  210.  
  211. #ifndef HAS_MEMMOVE
  212. #if defined(HAS_BCOPY) && defined(SAFE_BCOPY)
  213. #define memmove(d,s,l) bcopy(s,d,l)
  214. #else
  215. #if defined(HAS_MEMCPY) && defined(SAFE_MEMCPY)
  216. #define memmove(d,s,l) memcpy(d,s,l)
  217. #else
  218. #define memmove(d,s,l) my_bcopy(s,d,l)
  219. #endif
  220. #endif
  221. #endif
  222.  
  223. #ifndef _TYPES_        /* If types.h defines this it's easy. */
  224. #ifndef major        /* Does everyone's types.h define this? */
  225. #include <sys/types.h>
  226. #endif
  227. #endif
  228.  
  229. #ifdef I_NETINET_IN
  230. #include <netinet/in.h>
  231. #endif
  232.  
  233. #include <sys/stat.h>
  234. #if defined(uts) || defined(UTekV)
  235. #undef S_ISDIR
  236. #undef S_ISCHR
  237. #undef S_ISBLK
  238. #undef S_ISREG
  239. #undef S_ISFIFO
  240. #undef S_ISLNK
  241. #define S_ISDIR(P) (((P)&S_IFMT)==S_IFDIR)
  242. #define S_ISCHR(P) (((P)&S_IFMT)==S_IFCHR)
  243. #define S_ISBLK(P) (((P)&S_IFMT)==S_IFBLK)
  244. #define S_ISREG(P) (((P)&S_IFMT)==S_IFREG)
  245. #define S_ISFIFO(P) (((P)&S_IFMT)==S_IFIFO)
  246. #ifdef S_IFLNK
  247. #define S_ISLNK(P) (((P)&S_IFMT)==S_IFLNK)
  248. #endif
  249. #endif
  250.  
  251. #ifdef I_TIME
  252. #   include <time.h>
  253. #endif
  254.  
  255. #ifdef I_SYS_TIME
  256. #   ifdef SYSTIMEKERNEL
  257. #    define KERNEL
  258. #   endif
  259. #   include <sys/time.h>
  260. #   ifdef SYSTIMEKERNEL
  261. #    undef KERNEL
  262. #   endif
  263. #endif
  264.  
  265. #ifndef MSDOS
  266. #include <sys/times.h>
  267. #endif
  268.  
  269. #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
  270. #undef HAS_STRERROR
  271. #endif
  272.  
  273. #include <errno.h>
  274. #ifndef MSDOS
  275. #ifndef errno
  276. extern int errno;     /* ANSI allows errno to be an lvalue expr */
  277. #endif
  278. #endif
  279.  
  280. #ifndef strerror
  281. #ifdef HAS_STRERROR
  282. char *strerror();
  283. #else
  284. extern int sys_nerr;
  285. extern char *sys_errlist[];
  286. #define strerror(e) ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
  287. #endif
  288. #endif
  289.  
  290. #ifdef I_SYSIOCTL
  291. #ifndef _IOCTL_
  292. #include <sys/ioctl.h>
  293. #endif
  294. #endif
  295.  
  296. #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
  297. #ifdef HAS_SOCKETPAIR
  298. #undef HAS_SOCKETPAIR
  299. #endif
  300. #ifdef HAS_NDBM
  301. #undef HAS_NDBM
  302. #endif
  303. #endif
  304.  
  305. #ifdef WANT_DBZ
  306. #include <dbz.h>
  307. #define SOME_DBM
  308. #define dbm_fetch(db,dkey) fetch(dkey)
  309. #define dbm_delete(db,dkey) fatal("dbz doesn't implement delete")
  310. #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
  311. #define dbm_close(db) dbmclose()
  312. #define dbm_firstkey(db) (fatal("dbz doesn't implement traversal"),fetch())
  313. #define nextkey() (fatal("dbz doesn't implement traversal"),fetch())
  314. #define dbm_nextkey(db) (fatal("dbz doesn't implement traversal"),fetch())
  315. #ifdef HAS_NDBM
  316. #undef HAS_NDBM
  317. #endif
  318. #ifndef HAS_ODBM
  319. #define HAS_ODBM
  320. #endif
  321. #else
  322. #ifdef HAS_GDBM
  323. #ifdef I_GDBM
  324. #include <gdbm.h>
  325. #endif
  326. #define SOME_DBM
  327. #ifdef HAS_NDBM
  328. #undef HAS_NDBM
  329. #endif
  330. #ifdef HAS_ODBM
  331. #undef HAS_ODBM
  332. #endif
  333. #else
  334. #ifdef HAS_NDBM
  335. #include <ndbm.h>
  336. #define SOME_DBM
  337. #ifdef HAS_ODBM
  338. #undef HAS_ODBM
  339. #endif
  340. #else
  341. #ifdef HAS_ODBM
  342. #ifdef NULL
  343. #undef NULL        /* suppress redefinition message */
  344. #endif
  345. #include <dbm.h>
  346. #ifdef NULL
  347. #undef NULL
  348. #endif
  349. #define NULL 0        /* silly thing is, we don't even use this */
  350. #define SOME_DBM
  351. #define dbm_fetch(db,dkey) fetch(dkey)
  352. #define dbm_delete(db,dkey) delete(dkey)
  353. #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent)
  354. #define dbm_close(db) dbmclose()
  355. #define dbm_firstkey(db) firstkey()
  356. #endif /* HAS_ODBM */
  357. #endif /* HAS_NDBM */
  358. #endif /* HAS_GDBM */
  359. #endif /* WANT_DBZ */
  360. #ifdef SOME_DBM
  361. EXT char *dbmkey;
  362. EXT int dbmlen;
  363. #endif
  364.  
  365. #if INTSIZE == 2
  366. #define htoni htons
  367. #define ntohi ntohs
  368. #else
  369. #define htoni htonl
  370. #define ntohi ntohl
  371. #endif
  372.  
  373. #if defined(I_DIRENT)
  374. #   include <dirent.h>
  375. #   define DIRENT dirent
  376. #else
  377. #   ifdef I_SYS_NDIR
  378. #    include <sys/ndir.h>
  379. #    define DIRENT direct
  380. #   else
  381. #    ifdef I_SYS_DIR
  382. #        ifdef hp9000s500
  383. #        include <ndir.h>    /* may be wrong in the future */
  384. #        else
  385. #           ifndef __HIGHC__
  386. #                include <sys/dir.h>
  387. #           endif
  388. #        endif
  389. #        define DIRENT direct
  390. #    endif
  391. #   endif
  392. #endif
  393.  
  394. #ifdef FPUTS_BOTCH
  395. /* work around botch in SunOS 4.0.1 and 4.0.2 */
  396. #   ifndef fputs
  397. #    define fputs(str,fp) fprintf(fp,"%s",str)
  398. #   endif
  399. #endif
  400.  
  401. /*
  402.  * The following gobbledygook brought to you on behalf of __STDC__.
  403.  * (I could just use #ifndef __STDC__, but this is more bulletproof
  404.  * in the face of half-implementations.)
  405.  */
  406.  
  407. #ifndef S_IFMT
  408. #   ifdef _S_IFMT
  409. #    define S_IFMT _S_IFMT
  410. #   else
  411. #    define S_IFMT 0170000
  412. #   endif
  413. #endif
  414.  
  415. #ifndef S_ISDIR
  416. #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
  417. #endif
  418.  
  419. #ifndef S_ISCHR
  420. #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
  421. #endif
  422.  
  423. #ifndef S_ISBLK
  424. #   ifdef S_IFBLK
  425. #    define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
  426. #   else
  427. #    define S_ISBLK(m) (0)
  428. #   endif
  429. #endif
  430.  
  431. #ifndef S_ISREG
  432. #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
  433. #endif
  434.  
  435. #ifndef S_ISFIFO
  436. #   ifdef S_IFIFO
  437. #    define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
  438. #   else
  439. #    define S_ISFIFO(m) (0)
  440. #   endif
  441. #endif
  442.  
  443. #ifndef S_ISLNK
  444. #   ifdef _S_ISLNK
  445. #    define S_ISLNK(m) _S_ISLNK(m)
  446. #   else
  447. #    ifdef _S_IFLNK
  448. #        define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
  449. #    else
  450. #        ifdef S_IFLNK
  451. #        define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
  452. #        else
  453. #        define S_ISLNK(m) (0)
  454. #        endif
  455. #    endif
  456. #   endif
  457. #endif
  458.  
  459. #ifndef S_ISSOCK
  460. #   ifdef _S_ISSOCK
  461. #    define S_ISSOCK(m) _S_ISSOCK(m)
  462. #   else
  463. #    ifdef _S_IFSOCK
  464. #        define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
  465. #    else
  466. #        ifdef S_IFSOCK
  467. #        define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
  468. #        else
  469. #        define S_ISSOCK(m) (0)
  470. #        endif
  471. #    endif
  472. #   endif
  473. #endif
  474.  
  475. #ifndef S_IRUSR
  476. #   ifdef S_IREAD
  477. #    define S_IRUSR S_IREAD
  478. #    define S_IWUSR S_IWRITE
  479. #    define S_IXUSR S_IEXEC
  480. #   else
  481. #    define S_IRUSR 0400
  482. #    define S_IWUSR 0200
  483. #    define S_IXUSR 0100
  484. #   endif
  485. #   define S_IRGRP (S_IRUSR>>3)
  486. #   define S_IWGRP (S_IWUSR>>3)
  487. #   define S_IXGRP (S_IXUSR>>3)
  488. #   define S_IROTH (S_IRUSR>>6)
  489. #   define S_IWOTH (S_IWUSR>>6)
  490. #   define S_IXOTH (S_IXUSR>>6)
  491. #endif
  492.  
  493. #ifndef S_ISUID
  494. #   define S_ISUID 04000
  495. #endif
  496.  
  497. #ifndef S_ISGID
  498. #   define S_ISGID 02000
  499. #endif
  500.  
  501. #ifdef f_next
  502. #undef f_next
  503. #endif
  504.  
  505. #if defined(cray) || defined(gould) || defined(i860)
  506. #   define SLOPPYDIVIDE
  507. #endif
  508.  
  509. #if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
  510. #   define QUAD
  511. #endif
  512.  
  513. #ifdef QUAD
  514. #   ifdef cray
  515. #    define quad int
  516. #   else
  517. #    if defined(convex) || defined (uts)
  518. #        define quad long long
  519. #    else
  520. #        define quad long
  521. #    endif
  522. #   endif
  523. #endif
  524.  
  525. typedef MEM_SIZE STRLEN;
  526.  
  527. typedef struct arg ARG;
  528. typedef struct cmd CMD;
  529. typedef struct formcmd FCMD;
  530. typedef struct scanpat SPAT;
  531. typedef struct stio STIO;
  532. typedef struct sub SUBR;
  533. typedef struct string STR;
  534. typedef struct atbl ARRAY;
  535. typedef struct htbl HASH;
  536. typedef struct regexp REGEXP;
  537. typedef struct stabptrs STBP;
  538. typedef struct stab STAB;
  539. typedef struct callsave CSV;
  540.  
  541. #include "handy.h"
  542. #include "regexp.h"
  543. #include "str.h"
  544. #include "util.h"
  545. #include "form.h"
  546. #include "stab.h"
  547. #include "spat.h"
  548. #include "arg.h"
  549. #include "cmd.h"
  550. #include "array.h"
  551. #include "hash.h"
  552.  
  553. #if defined(iAPX286) || defined(M_I286) || defined(I80286)
  554. #   define I286
  555. #endif
  556.  
  557. #ifndef    STANDARD_C
  558. #ifdef CHARSPRINTF
  559.     char *sprintf();
  560. #else
  561.     int sprintf();
  562. #endif
  563. #endif
  564.  
  565. EXT char *Yes INIT("1");
  566. EXT char *No INIT("");
  567.  
  568. /* "gimme" values */
  569.  
  570. /* Note: cmd.c assumes that it can use && to produce one of these values! */
  571. #define G_SCALAR 0
  572. #define G_ARRAY 1
  573.  
  574. #ifdef CRIPPLED_CC
  575. int str_true();
  576. #else /* !CRIPPLED_CC */
  577. #define str_true(str) (Str = (str), \
  578.     (Str->str_pok ? \
  579.         ((*Str->str_ptr > '0' || \
  580.           Str->str_cur > 1 || \
  581.           (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \
  582.     : \
  583.         (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) ))
  584. #endif /* CRIPPLED_CC */
  585.  
  586. #ifdef DEBUGGING
  587. #define str_peek(str) (Str = (str), \
  588.     (Str->str_pok ? \
  589.         Str->str_ptr : \
  590.         (Str->str_nok ? \
  591.         (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \
  592.             (char*)tokenbuf) : \
  593.         "" )))
  594. #endif
  595.  
  596. #ifdef CRIPPLED_CC
  597. char *str_get();
  598. #else
  599. #ifdef TAINT
  600. #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \
  601.     (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  602. #else
  603. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  604. #endif /* TAINT */
  605. #endif /* CRIPPLED_CC */
  606.  
  607. #ifdef CRIPPLED_CC
  608. double str_gnum();
  609. #else /* !CRIPPLED_CC */
  610. #ifdef TAINT
  611. #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \
  612.     (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
  613. #else /* !TAINT */
  614. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str)))
  615. #endif /* TAINT*/
  616. #endif /* CRIPPLED_CC */
  617. EXT STR *Str;
  618.  
  619. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  620.  
  621. #ifndef DOSISH
  622. #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len)
  623. #define Str_Grow str_grow
  624. #else
  625. /* extra parentheses intentionally NOT placed around "len"! */
  626. #define STR_GROW(str,len) if ((str)->str_len < (unsigned long)len) \
  627.         str_grow(str,(unsigned long)len)
  628. #define Str_Grow(str,len) str_grow(str,(unsigned long)(len))
  629. #endif /* DOSISH */
  630.  
  631. #ifndef BYTEORDER
  632. #define BYTEORDER 0x1234
  633. #endif
  634.  
  635. #if defined(htonl) && !defined(HAS_HTONL)
  636. #define HAS_HTONL
  637. #endif
  638. #if defined(htons) && !defined(HAS_HTONS)
  639. #define HAS_HTONS
  640. #endif
  641. #if defined(ntohl) && !defined(HAS_NTOHL)
  642. #define HAS_NTOHL
  643. #endif
  644. #if defined(ntohs) && !defined(HAS_NTOHS)
  645. #define HAS_NTOHS
  646. #endif
  647. #ifndef HAS_HTONL
  648. #if (BYTEORDER & 0xffff) != 0x4321
  649. #define HAS_HTONS
  650. #define HAS_HTONL
  651. #define HAS_NTOHS
  652. #define HAS_NTOHL
  653. #define MYSWAP
  654. #define htons my_swap
  655. #define htonl my_htonl
  656. #define ntohs my_swap
  657. #define ntohl my_ntohl
  658. #endif
  659. #else
  660. #if (BYTEORDER & 0xffff) == 0x4321
  661. #undef HAS_HTONS
  662. #undef HAS_HTONL
  663. #undef HAS_NTOHS
  664. #undef HAS_NTOHL
  665. #endif
  666. #endif
  667.  
  668. /*
  669.  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
  670.  * -DWS
  671.  */
  672. #if BYTEORDER != 0x1234
  673. # define HAS_VTOHL
  674. # define HAS_VTOHS
  675. # define HAS_HTOVL
  676. # define HAS_HTOVS
  677. # if BYTEORDER == 0x4321
  678. #  define vtohl(x)    ((((x)&0xFF)<<24)    \
  679.             +(((x)>>24)&0xFF)    \
  680.             +(((x)&0x0000FF00)<<8)    \
  681.             +(((x)&0x00FF0000)>>8)    )
  682. #  define vtohs(x)    ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
  683. #  define htovl(x)    vtohl(x)
  684. #  define htovs(x)    vtohs(x)
  685. # endif
  686.     /* otherwise default to functions in util.c */
  687. #endif
  688.  
  689. #ifdef CASTNEGFLOAT
  690. #define U_S(what) ((unsigned short)(what))
  691. #define U_I(what) ((unsigned int)(what))
  692. #define U_L(what) ((unsigned long)(what))
  693. #else
  694. unsigned long castulong();
  695. #define U_S(what) ((unsigned int)castulong(what))
  696. #define U_I(what) ((unsigned int)castulong(what))
  697. #define U_L(what) (castulong(what))
  698. #endif
  699.  
  700. CMD *add_label();
  701. CMD *block_head();
  702. CMD *append_line();
  703. CMD *make_acmd();
  704. CMD *make_ccmd();
  705. CMD *make_icmd();
  706. CMD *invert();
  707. CMD *addcond();
  708. CMD *addloop();
  709. CMD *wopt();
  710. CMD *over();
  711.  
  712. STAB *stabent();
  713. STAB *genstab();
  714.  
  715. ARG *stab2arg();
  716. ARG *op_new();
  717. ARG *make_op();
  718. ARG *make_match();
  719. ARG *make_split();
  720. ARG *rcatmaybe();
  721. ARG *listish();
  722. ARG *maybelistish();
  723. ARG *localize();
  724. ARG *fixeval();
  725. ARG *jmaybe();
  726. ARG *l();
  727. ARG *fixl();
  728. ARG *mod_match();
  729. ARG *make_list();
  730. ARG *cmd_to_arg();
  731. ARG *addflags();
  732. ARG *hide_ary();
  733. ARG *cval_to_arg();
  734.  
  735. STR *str_new();
  736. STR *stab_str();
  737.  
  738. int apply();
  739. int do_each();
  740. int do_subr();
  741. int do_match();
  742. int do_unpack();
  743. int eval();        /* this evaluates expressions */
  744. int do_eval();        /* this evaluates eval operator */
  745. int do_assign();
  746.  
  747. SUBR *make_sub();
  748.  
  749. FCMD *load_format();
  750.  
  751. char *scanpat();
  752. char *scansubst();
  753. char *scantrans();
  754. char *scanstr();
  755. char *scanident();
  756. char *str_append_till();
  757. char *str_gets();
  758. char *str_grow();
  759.  
  760. bool do_open();
  761. bool do_close();
  762. bool do_print();
  763. bool do_aprint();
  764. bool do_exec();
  765. bool do_aexec();
  766.  
  767. int do_subst();
  768. int cando();
  769. int ingroup();
  770. int whichsig();
  771. int userinit();
  772. #ifdef CRYPTSCRIPT
  773. void cryptswitch();
  774. #endif
  775.  
  776. void str_replace();
  777. void str_inc();
  778. void str_dec();
  779. void str_free();
  780. void cmd_free();
  781. void arg_free();
  782. void spat_free();
  783. void regfree();
  784. void stab_clear();
  785. void do_chop();
  786. void do_vop();
  787. void do_write();
  788. void do_join();
  789. void do_sprintf();
  790. void do_accept();
  791. void do_pipe();
  792. void do_vecset();
  793. void do_unshift();
  794. void do_execfree();
  795. void magicalize();
  796. void magicname();
  797. void savelist();
  798. void saveitem();
  799. void saveint();
  800. void savelong();
  801. void savesptr();
  802. void savehptr();
  803. void restorelist();
  804. void repeatcpy();
  805. void make_form();
  806. void dehoist();
  807. void format();
  808. void my_unexec();
  809.  
  810. #ifdef __HIGHC__
  811. int fatal(const char *pat, ...);
  812. int warn(const char *pat, ...);
  813. #else 
  814. void fatal();
  815. void warn();
  816. #endif 
  817.  
  818. #ifdef DEBUGGING
  819. void dump_all();
  820. void dump_cmd();
  821. void dump_arg();
  822. void dump_flags();
  823. void dump_stab();
  824. void dump_spat();
  825. #endif
  826. #ifdef MSTATS
  827. void mstats();
  828. #endif
  829.  
  830. HASH *savehash();
  831. ARRAY *saveary();
  832.  
  833. EXT char **origargv;
  834. EXT int origargc;
  835. EXT char **origenviron;
  836. extern char **environ;
  837.  
  838. EXT long subline INIT(0);
  839. EXT STR *subname INIT(Nullstr);
  840. EXT int arybase INIT(0);
  841.  
  842. struct outrec {
  843.     long    o_lines;
  844.     char    *o_str;
  845.     int        o_len;
  846. };
  847.  
  848. EXT struct outrec outrec;
  849. EXT struct outrec toprec;
  850.  
  851. EXT STAB *stdinstab INIT(Nullstab);
  852. EXT STAB *last_in_stab INIT(Nullstab);
  853. EXT STAB *defstab INIT(Nullstab);
  854. EXT STAB *argvstab INIT(Nullstab);
  855. EXT STAB *envstab INIT(Nullstab);
  856. EXT STAB *sigstab INIT(Nullstab);
  857. EXT STAB *defoutstab INIT(Nullstab);
  858. EXT STAB *curoutstab INIT(Nullstab);
  859. EXT STAB *argvoutstab INIT(Nullstab);
  860. EXT STAB *incstab INIT(Nullstab);
  861. EXT STAB *leftstab INIT(Nullstab);
  862. EXT STAB *amperstab INIT(Nullstab);
  863. EXT STAB *rightstab INIT(Nullstab);
  864. EXT STAB *DBstab INIT(Nullstab);
  865. EXT STAB *DBline INIT(Nullstab);
  866. EXT STAB *DBsub INIT(Nullstab);
  867.  
  868. EXT HASH *defstash;        /* main symbol table */
  869. EXT HASH *curstash;        /* symbol table for current package */
  870. EXT HASH *debstash;        /* symbol table for perldb package */
  871.  
  872. EXT STR *curstname;        /* name of current package */
  873.  
  874. EXT STR *freestrroot INIT(Nullstr);
  875. EXT STR *lastretstr INIT(Nullstr);
  876. EXT STR *DBsingle INIT(Nullstr);
  877. EXT STR *DBtrace INIT(Nullstr);
  878. EXT STR *DBsignal INIT(Nullstr);
  879. EXT STR *formfeed INIT(Nullstr);
  880.  
  881. EXT int lastspbase;
  882. EXT int lastsize;
  883.  
  884. EXT char *hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
  885. EXT char *origfilename;
  886. EXT FILE * VOLATILE rsfp;
  887. EXT char buf[1024];
  888. EXT char *bufptr;
  889. EXT char *oldbufptr;
  890. EXT char *oldoldbufptr;
  891. EXT char *bufend;
  892.  
  893. EXT STR *linestr INIT(Nullstr);
  894.  
  895. EXT char *rs INIT("\n");
  896. EXT int rschar INIT('\n');    /* final char of rs, or 0777 if none */
  897. EXT int rslen INIT(1);
  898. EXT bool rspara INIT(FALSE);
  899. EXT char *ofs INIT(Nullch);
  900. EXT int ofslen INIT(0);
  901. EXT char *ors INIT(Nullch);
  902. EXT int orslen INIT(0);
  903. EXT char *ofmt INIT(Nullch);
  904. EXT char *inplace INIT(Nullch);
  905. EXT char *nointrp INIT("");
  906.  
  907. EXT bool preprocess INIT(FALSE);
  908. EXT bool minus_n INIT(FALSE);
  909. EXT bool minus_p INIT(FALSE);
  910. EXT bool minus_l INIT(FALSE);
  911. EXT bool minus_a INIT(FALSE);
  912. EXT bool doswitches INIT(FALSE);
  913. EXT bool dowarn INIT(FALSE);
  914. EXT bool doextract INIT(FALSE);
  915. EXT bool allstabs INIT(FALSE);    /* init all customary symbols in symbol table?*/
  916. EXT bool sawampersand INIT(FALSE);    /* must save all match strings */
  917. EXT bool sawstudy INIT(FALSE);        /* do fbminstr on all strings */
  918. EXT bool sawi INIT(FALSE);        /* study must assume case insensitive */
  919. EXT bool sawvec INIT(FALSE);
  920. EXT bool localizing INIT(FALSE);    /* are we processing a local() list? */
  921.  
  922. #ifndef MAXSYSFD
  923. #   define MAXSYSFD 2
  924. #endif
  925. EXT int maxsysfd INIT(MAXSYSFD);    /* top fd to pass to subprocesses */
  926.  
  927. #ifdef CSH
  928. EXT char *cshname INIT(CSH);
  929. EXT int cshlen INIT(0);
  930. #endif /* CSH */
  931.  
  932. #ifdef TAINT
  933. EXT bool tainted INIT(FALSE);        /* using variables controlled by $< */
  934. EXT bool taintanyway INIT(FALSE);    /* force taint checks when !set?id */
  935. #endif
  936.  
  937. EXT bool nomemok INIT(FALSE);        /* let malloc context handle nomem */
  938.  
  939. #ifndef DOSISH
  940. #define TMPPATH "/tmp/perl-eXXXXXX"
  941. #else
  942. #define TMPPATH "plXXXXXX"
  943. #endif /* MSDOS */
  944. EXT char *e_tmpname;
  945. EXT FILE *e_fp INIT(Nullfp);
  946.  
  947. EXT char tokenbuf[256];
  948. EXT int expectterm INIT(TRUE);        /* how to interpret ambiguous tokens */
  949. EXT VOLATILE int in_eval INIT(FALSE);    /* trap fatal errors? */
  950. EXT int multiline INIT(0);        /* $*--do strings hold >1 line? */
  951. EXT int forkprocess;            /* so do_open |- can return proc# */
  952. EXT int do_undump INIT(0);        /* -u or dump seen? */
  953. EXT int error_count INIT(0);        /* how many errors so far, max 10 */
  954. EXT int multi_start INIT(0);        /* 1st line of multi-line string */
  955. EXT int multi_end INIT(0);        /* last line of multi-line string */
  956. EXT int multi_open INIT(0);        /* delimiter of said string */
  957. EXT int multi_close INIT(0);        /* delimiter of said string */
  958.  
  959. FILE *popen();
  960. /* char *str_get(); */
  961. STR *interp();
  962. void free_arg();
  963. STIO *stio_new();
  964. void hoistmust();
  965. void scanconst();
  966.  
  967. EXT struct stat statbuf;
  968. EXT struct stat statcache;
  969. EXT STAB *statstab INIT(Nullstab);
  970. EXT STR *statname;
  971. #ifndef MSDOS
  972. EXT struct tms timesbuf;
  973. #endif
  974. EXT int uid;
  975. EXT int euid;
  976. EXT int gid;
  977. EXT int egid;
  978. UIDTYPE getuid();
  979. UIDTYPE geteuid();
  980. GIDTYPE getgid();
  981. GIDTYPE getegid();
  982. EXT int unsafe;
  983.  
  984. #ifdef DEBUGGING
  985. EXT VOLATILE int debug INIT(0);
  986. EXT int dlevel INIT(0);
  987. EXT int dlmax INIT(128);
  988. EXT char *debname;
  989. EXT char *debdelim;
  990. #define YYDEBUG 1
  991. #endif
  992. EXT int perldb INIT(0);
  993. #define YYMAXDEPTH 300
  994.  
  995. EXT line_t cmdline INIT(NOLINE);
  996.  
  997. EXT STR str_undef;
  998. EXT STR str_no;
  999. EXT STR str_yes;
  1000.  
  1001. /* runtime control stuff */
  1002.  
  1003. EXT struct loop {
  1004.     char *loop_label;        /* what the loop was called, if anything */
  1005.     int loop_sp;        /* stack pointer to copy stuff down to */
  1006.     jmp_buf loop_env;
  1007. } *loop_stack;
  1008.  
  1009. EXT int loop_ptr INIT(-1);
  1010. EXT int loop_max INIT(128);
  1011.  
  1012. EXT jmp_buf top_env;
  1013.  
  1014. EXT char * VOLATILE goto_targ INIT(Nullch); /* cmd_exec gets strange when set */
  1015.  
  1016. struct ufuncs {
  1017.     int (*uf_val)();
  1018.     int (*uf_set)();
  1019.     int uf_index;
  1020. };
  1021.  
  1022. EXT ARRAY *stack;        /* THE STACK */
  1023.  
  1024. EXT ARRAY * VOLATILE savestack;        /* to save non-local values on */
  1025.  
  1026. EXT ARRAY *tosave;        /* strings to save on recursive subroutine */
  1027.  
  1028. EXT ARRAY *lineary;        /* lines of script for debugger */
  1029. EXT ARRAY *dbargs;        /* args to call listed by caller function */
  1030.  
  1031. EXT ARRAY *fdpid;        /* keep fd-to-pid mappings for mypopen */
  1032. EXT HASH *pidstatus;        /* keep pid-to-status mappings for waitpid */
  1033.  
  1034. EXT int *di;            /* for tmp use in debuggers */
  1035. EXT char *dc;
  1036. EXT short *ds;
  1037.  
  1038. /* Fix these up for __STDC__ */
  1039. EXT time_t basetime INIT(0);
  1040. char *mktemp();
  1041. #ifndef STANDARD_C
  1042. /* All of these are in stdlib.h or time.h for ANSI C */
  1043. double atof();
  1044. long time();
  1045. struct tm *gmtime(), *localtime();
  1046. char *index(), *rindex();
  1047. char *strcpy(), *strcat();
  1048. #endif /* ! STANDARD_C */
  1049.  
  1050. #ifdef EUNICE
  1051. #define UNLINK unlnk
  1052. int unlnk();
  1053. #else
  1054. #define UNLINK unlink
  1055. #endif
  1056.  
  1057. #ifndef HAS_SETREUID
  1058. #ifdef HAS_SETRESUID
  1059. #define setreuid(r,e) setresuid(r,e,-1)
  1060. #define HAS_SETREUID
  1061. #endif
  1062. #endif
  1063. #ifndef HAS_SETREGID
  1064. #ifdef HAS_SETRESGID
  1065. #define setregid(r,e) setresgid(r,e,-1)
  1066. #define HAS_SETREGID
  1067. #endif
  1068. #endif
  1069.  
  1070. #define SCAN_DEF 0
  1071. #define SCAN_TR 1
  1072. #define SCAN_REPL 2
  1073.